
# SPDX-FileCopyrightText: 2021 Camilo Higuita <milo.h@aol.com>
#
# SPDX-License-Identifier: BSD-2-Clause

cmake_minimum_required(VERSION 3.16)

project(CaskPolkit LANGUAGES CXX VERSION 0.5.0)

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(AUTOMOC_MOC_OPTIONS -Muri=org.cask.polkit)

include(GenerateExportHeader)
include(CMakePackageConfigHelpers)

include(ECMGenerateQmlTypes)
include(ECMGenerateHeaders)
include(ECMFindQmlModule)
include(ECMQmlModule)

include(KDEClangFormat)
include(KDEInstallDirs)
include(KDECMakeSettings)

set(CMAKECONFIG_INSTALL_DIR "${KDE_INSTALL_CMAKEPACKAGEDIR}/CaskPolkit")

configure_package_config_file(
    "${CMAKE_CURRENT_SOURCE_DIR}/CaskPolkitConfig.cmake.in"
    "${CMAKE_CURRENT_BINARY_DIR}/CaskPolkitConfig.cmake"
    INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR}
    PATH_VARS CMAKE_INSTALL_PREFIX)

install(FILES
    "${CMAKE_CURRENT_BINARY_DIR}/CaskPolkitConfigVersion.cmake"
    "${CMAKE_CURRENT_BINARY_DIR}/CaskPolkitConfig.cmake"
    DESTINATION "${CMAKECONFIG_INSTALL_DIR}"
    COMPONENT Devel)

install(EXPORT CaskPolkitTargets
    DESTINATION "${CMAKECONFIG_INSTALL_DIR}"
    FILE CaskPolkit.cmake
    NAMESPACE Cask::)

ecm_setup_version(${PROJECT_VERSION}
    VARIABLE_PREFIX ${PROJECT_NAME}
    VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/CaskPolkit_version.h"
    PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/CaskPolkitConfigVersion.cmake"
    SOVERSION ${PROJECT_VERSION_MAJOR})

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/CaskPolkit_version.h"
    DESTINATION ${KDE_INSTALL_INCLUDEDIR}/Cask/Power
    COMPONENT Devel)

find_package(PkgConfig)
pkg_check_modules(POLKIT_AGENT REQUIRED polkit-agent-1)
message(STATUS "polkit agent: ${POLKIT_AGENT_INCLUDE_DIRS} ${POLKIT_AGENT_LIBRARIES}")

find_package(PolkitQt6-1 REQUIRED)

include_directories(
    ${POLKIT_AGENT_INCLUDE_DIRS}
    "${POLKITQT-1_INCLUDE_DIR}")

find_package(Qt6 ${REQUIRED_QT_VERSION} REQUIRED COMPONENTS
    Core
    Qml
    Quick
    DBus
    Gui)

find_package(KF6 ${REQUIRED_KF_VERSION} REQUIRED COMPONENTS
    I18n
    Solid
    IdleTime
    CoreAddons
    Service)

add_subdirectory(src)

feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES)

